package com.hunan.api.catv.service.biz.banner;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hunan.api.catv.entity.po.IndexBanner;
import com.hunan.api.catv.entity.vo.IndexBannerVo;
import com.hunan.api.catv.service.ResultService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jiang zhuan
 * @version 1.0
 * @description 描述
 * @date 2021/11/25 0025
 * @package com.hunan.api.catv.service.biz.banner
 * @company 湖南有线
 */
@Service
public class IndexBannerBiz extends ResultService {

    public Object getBannerList() {
        List<IndexBanner> indexBanners = new IndexBanner().selectList(new QueryWrapper<IndexBanner>().eq(IndexBanner.STATE, 1).eq(IndexBanner.DELETED, 1).eq(IndexBanner.TYPE, 0).orderByDesc(IndexBanner.SEQ));
        List<IndexBannerVo> collect = indexBanners.stream().map(indexBanner -> {
            IndexBannerVo indexBannerVo = new IndexBannerVo();
            BeanUtil.copyProperties(indexBanner, indexBannerVo);
            if (indexBanner.getTarget().equals(1)) {
                JSONObject jsonObject = JSONUtil.parseObj(indexBanner.getLink());
                indexBannerVo.setAndroidLink(jsonObject.getStr("android"));
                indexBannerVo.setIosLink(jsonObject.getStr("ios"));
            } else {
                indexBannerVo.setAndroidLink(indexBanner.getLink());
                indexBannerVo.setIosLink(indexBanner.getLink());
            }
            return indexBannerVo;
        }).collect(Collectors.toList());
        return collect;
    }
}
